package mylittleinvestigations.GameUi;

import mylittleinvestigations.CaseInformation.Case;
import mylittleinvestigations.Partner;
import mylittleinvestigations.PersistentThreads.RenderThread;
import mylittleinvestigations.Utils;
import mylittleinvestigations.Vector2;
import org.newdawn.slick.*;
import org.newdawn.slick.geom.*;

public class PartnerInformation
{
    private static final Vector2 backgroundTexturePosition = new Vector2(7, 8);
    private static final Rectangle partnerNameRectangle = new Rectangle(10, 11, 220, 42);
    private static final Vector2 profileImagePosition = new Vector2(10, 56);
    private static final Vector2 passiveAbilityHeadingPosition = new Vector2(252, 33);
    private static final Vector2 passiveAbilityDescriptionPosition = new Vector2(269, 75);
    private static final Vector2 activeAbilityHeadingPosition = new Vector2(252, 154);
    private static final Vector2 activeAbilityDescriptionPosition = new Vector2(269, 197);

    private static Image backgroundTexture;
    private static UnicodeFont headingFont;
    private static UnicodeFont bodyFont;

    private Partner partner;
    private String partnerId;

    public static void Initialize(Image backgroundTexture, UnicodeFont headingFont, UnicodeFont bodyFont)
    {
        PartnerInformation.backgroundTexture = backgroundTexture;
        PartnerInformation.headingFont = headingFont;
        PartnerInformation.bodyFont = bodyFont;
    }

    public PartnerInformation()
    {
        this.partner = null;
        this.partnerId = null;
    }

    public String getPartnerId()
    {
        return this.partnerId;
    }

    public void setPartnerId(String partnerId)
    {
        if (!Utils.equals(partnerId, this.partnerId))
        {
            this.partnerId = partnerId;
            this.partner = Case.getInstance().getPartnerManager().GetPartnerFromId(this.partnerId);
        }
    }

    public void Draw(GameContainer gc, Graphics g, int xOffset)
    {
        this.Draw(gc, g, xOffset, 0);
    }

    public void Draw(GameContainer gc, Graphics g, int xOffset, float yOffset)
    {
        if (this.partner == null)
        {
            return;
        }

        Vector2 offsetVector = new Vector2(xOffset, yOffset);
        Vector2 partnerNamePosition =
            new Vector2(
                partnerNameRectangle.getX() + partnerNameRectangle.getWidth() / 2 - headingFont.getWidth(this.partner.getName()) / 2,
                partnerNameRectangle.getY() + partnerNameRectangle.getHeight() / 2 - headingFont.getHeight(this.partner.getName()) / 2 + 5);
        partnerNamePosition = new Vector2((float)Math.round(partnerNamePosition.getX()), (float)Math.round(partnerNamePosition.getY()));
        
        RenderThread.getInstance().AddImageToRenderQueue(backgroundTexture, (float)backgroundTexturePosition.add(offsetVector).getX(), (float)backgroundTexturePosition.add(offsetVector).getY());
        RenderThread.getInstance().AddStringToRenderQueue(headingFont, (float)partnerNamePosition.add(offsetVector).getX(), (float)partnerNamePosition.add(offsetVector).getY(), this.partner.getName());
        this.partner.getProfileImageSprite().Draw(gc, g, profileImagePosition.add(offsetVector));
        RenderThread.getInstance().AddStringToRenderQueue(headingFont, (float)passiveAbilityHeadingPosition.add(offsetVector).getX(), (float)passiveAbilityHeadingPosition.add(offsetVector).getY(), "Passive ability");
        RenderThread.getInstance().AddStringToRenderQueue(bodyFont, (float)passiveAbilityDescriptionPosition.add(offsetVector).getX(), (float)passiveAbilityDescriptionPosition.add(offsetVector).getY(), this.partner.getPassiveAbilityDescription());
        RenderThread.getInstance().AddStringToRenderQueue(headingFont, (float)activeAbilityHeadingPosition.add(offsetVector).getX(), (float)activeAbilityHeadingPosition.add(offsetVector).getY(), "Active ability");
        RenderThread.getInstance().AddStringToRenderQueue(bodyFont, (float)activeAbilityDescriptionPosition.add(offsetVector).getX(), (float)activeAbilityDescriptionPosition.add(offsetVector).getY(), this.partner.getActiveAbilityDescription());
    }
}